Skip to content

Use native variable validation#14

Open
haampie wants to merge 3 commits into
mainfrom
hs/fix/input-validation
Open

Use native variable validation#14
haampie wants to merge 3 commits into
mainfrom
hs/fix/input-validation

Conversation

@haampie
Copy link
Copy Markdown
Member

@haampie haampie commented May 15, 2026

  • Use null utility : ... to avoid execution
  • Use ${parameter:?[word]} to ensure the variable is set
  • Drop eval loop

The error message on Ubuntu reads:

dash: cc.sh: 205: SPACK_COMPILER_WRAPPER_PATH: Error: the compiler wrapper must be invoked from Spack
zsh: cc.sh:205: SPACK_COMPILER_WRAPPER_PATH: Error: the compiler wrapper must be invoked from Spack
bash: cc.sh: line 205: SPACK_COMPILER_WRAPPER_PATH: Error: the compiler wrapper must be invoked from Spack

Previously it was:

[spack cc]: Error: Spack compiler must be run from Spack! Input 'SPACK_COMPILER_WRAPPER_PATH' is missing.

haampie added 2 commits May 15, 2026 12:13
* Use null utility `: ...` to avoid execution
* Use `${parameter:?[word]}` to do ensure the variable is set
* Drop `eval` loop

The error message on Ubuntu reads:

> cc.sh: 205: SPACK_COMPILER_WRAPPER_PATH: Error: compiler wrapper must be invoked by Spack

Previously it was:

> [spack cc]: Error: Spack compiler must be run from Spack! Input 'SPACK_COMPILER_WRAPPER_PATH' is missing.

Signed-off-by: Harmen Stoppels <me@harmenstoppels.nl>
Signed-off-by: Harmen Stoppels <me@harmenstoppels.nl>
@haampie haampie force-pushed the hs/fix/input-validation branch from bdecef3 to af82ea1 Compare May 15, 2026 10:18
Signed-off-by: Harmen Stoppels <me@harmenstoppels.nl>
@haampie haampie force-pushed the hs/fix/input-validation branch from af82ea1 to ea60e01 Compare May 15, 2026 10:19
Comment thread cc.sh
fi
done
# Ensure required variables are set
: "${SPACK_COMPILER_WRAPPER_PATH:?Error: the compiler wrapper must be invoked from Spack}"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require_spack_env()
{
    _msg="Error: the compiler wrapper must be invoked from Spack"
    eval '": \"\${$1:?$_msg}\""
}

require_spack_env SPACK_COMPILER_WRAPPER_PATH
require_spack_env SPACK_DEBUG_LOG_DIR
require_spack_env SPACK_DEBUG_LOG_ID
require_spack_env SPACK_SHORT_SPEC
require_spack_env SPACK_SYSTEM_DIRS
require_spack_env SPACK_MANAGED_DIRS

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of my goals was to get rid of eval

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing I really want is the pull the message out as a variable to not have to copy-paste the string. idk what I was doing wrong earlier, but it seems you should be able to do

_msg="..."
: "${SPACK_VAR:?$_msg}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants